package com.mycompany.delivery.validation;


import com.mycompany.delivery.dto.ContactDTO;
import com.mycompany.delivery.dto.DeliveryDTO;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * 
 *
 * 
 * @author Jana Němcová
 */
public class DeliverySpringValidator implements Validator {

    @Override
    public boolean supports(Class<?> clazz) {
        return DeliveryDTO.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        DeliveryDTO del = (DeliveryDTO) target;
         ValidationUtils.rejectIfEmptyOrWhitespace(errors, "price", "price.null");
       
        if (del.getPrice()<=0) {
            errors.rejectValue("price", "price.null");
        }
     
    }
}
